﻿CREATE TABLE [org].[Unit] (
    [UnitId]         INT          IDENTITY (1, 1) NOT NULL,
    [UnitUniqueCode] AS           (CONVERT([char](7),[UnitCateryCode]+right('0000'+ltrim(rtrim([UnitCode])),(5)),(0))),
    [UnitCode]       VARCHAR (5)  NOT NULL,
    [UnitName]       VARCHAR (50) NOT NULL,
    [UnitCateryId]   SMALLINT     NOT NULL,
    [UnitCateryCode] CHAR (2)     NOT NULL,
    [UnitStartDate]  DATE         NOT NULL,
    [UnitEndDate]    DATE         NULL,
    [IsLatest]       BIT          NOT NULL,
    [IsActive]       BIT          NOT NULL,
    [IsInternal]     BIT          NOT NULL,
    [LegacyUnitId]   INT          NULL,
    [LegacyUnitCode] VARCHAR (50) NULL,
    PRIMARY KEY CLUSTERED ([UnitId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF)
);

